package com.aios.util;

import java.io.IOException;
import org.apache.log4j.Logger;

import com.aios.util.HttpClientAdaptor.HttpClientResponse;

public class HttpClientExecuter {

	private static Logger logger = Logger.getLogger(HttpClientExecuter.class);

	public static HttpClientResponse getAiosControllerResponse (
			String protocol, String host, String port, String username, 
			String password, String uri, boolean cacheStatus) {

		try {
			
			HttpClientAdaptor client = new HttpClientAdaptor(host, port, username, password, cacheStatus);
			
			/*String url = AiosAccessUtil.PROTOCOL + AiosAccessUtil.PROTOCOL_SEPERATOR +
					host + AiosAccessUtil.PORT_SEPERATOR + port + uri;*/
			String url = protocol + AiosAccessUtil.PROTOCOL_SEPERATOR + host + AiosAccessUtil.PORT_SEPERATOR + port + uri;
			
			HttpClientResponse aiosResponse = client.execute(url);
			//logger.info("NB202 response:"+aiosResponse.getResponseText());
			return aiosResponse;

		} catch (IOException e) {
			logger.error(e);
		}

		return null;

	}
	
	public static HttpClientResponse getAiosChangeOperation (
			String protocol, String host, String port, String username, String password, 
			String uri, String switchNumber, boolean cacheStatus) {

		try {
			
			HttpClientAdaptor client = new HttpClientAdaptor(host, port, username, password, cacheStatus);
			
			String url = protocol + AiosAccessUtil.PROTOCOL_SEPERATOR + host + 
					AiosAccessUtil.PORT_SEPERATOR + port + uri + switchNumber;
			
			HttpClientResponse aiosResponse = client.execute(url);
			//System.out.println("B:"+aiosResponse.getResponseText());
			logger.info("Timer Execution->"+aiosResponse.getResponseText());
			return aiosResponse;

		} catch (IOException e) {
			logger.error(e);
		}

		return null;

	}
	public static HttpClientResponse getCameraChangeDirection(
			String protocol, String host, String port, String username, 
			String password, String uri, String direction,boolean cacheStatus){
		

		try {
			
			HttpClientAdaptor client = new HttpClientAdaptor(host, port, username, password, cacheStatus);
			
			String url = protocol + AiosAccessUtil.PROTOCOL_SEPERATOR + host + 
					AiosAccessUtil.PORT_SEPERATOR + port + uri + direction;
			
			HttpClientResponse aiosResponse = client.execute(url);
			System.out.println(aiosResponse.toString());
			return aiosResponse;

		} catch (IOException e) {
			logger.error(e);
		}
	
	return null;
	}
	
	public static HttpClientResponse getCameraChangeZoom(
			String protocol, String host, String port, String username, 
			String password, String uri, String mode,boolean cacheStatus){
		

		try {
			
			HttpClientAdaptor client = new HttpClientAdaptor(host, port, username, password, cacheStatus);
			
			String url = protocol + AiosAccessUtil.PROTOCOL_SEPERATOR + host + 
					AiosAccessUtil.PORT_SEPERATOR + port + uri + mode;
			
			HttpClientResponse aiosResponse = client.execute(url);
			
			return aiosResponse;

		} catch (IOException e) {
			logger.error(e);
		}
	
	return null;
	}
	
}
